package cn.iocoder.yudao.module.system.controller.admin.template;


import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.admin.template.vo.PersonalTemplateCreateReqVO;
import cn.iocoder.yudao.module.system.controller.admin.template.vo.PersonalTemplateRespVO;
import cn.iocoder.yudao.module.system.controller.admin.template.vo.PersonalTemplateUpdateReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.template.SystemTemplate;
import cn.iocoder.yudao.module.system.dal.dataobject.template.Template;
import cn.iocoder.yudao.module.system.service.template.TemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "全媒体编辑 - 一键排版")
@RestController
@RequestMapping("/system/template")
@Validated
public class TemplateController {


    @Autowired
    TemplateService service;


    @GetMapping("/sysList")
    @Operation(summary = "获取系统一键排版列表")
    public CommonResult<List<SystemTemplate>> getSysList() {
        List<SystemTemplate> list = service.getALLSystemTemplate();
        return success(list);
    }

    @PostMapping("create")
    @Operation(summary = "创建个人一键排版")
    //@PreAuthorize("@ss.hasPermission('system:dept:create')")
    public CommonResult<Boolean> create( PersonalTemplateCreateReqVO reqVO) {
        service.addPersonalTemplate(reqVO);
        return success(true);
    }

    @PutMapping("update")
    @Operation(summary = "更新个人一键排版")
    //@PreAuthorize("@ss.hasPermission('system:dept:update')")
    public CommonResult<Boolean> update(PersonalTemplateUpdateReqVO reqVO) {
        service.updatePersonalTemplate(reqVO);
        return success(true);
    }

    @DeleteMapping("delete")
    @Operation(summary = "删除个人一键排版")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    //@PreAuthorize("@ss.hasPermission('system:dept:delete')")
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        service.removePersonalTemplateById(id);
        return success(true);
    }

    @GetMapping("/list")
    @Operation(summary = "获取个人一键排版列表")
    //@PreAuthorize("@ss.hasPermission('system:dept:query')")
    public CommonResult<List<PersonalTemplateRespVO>> getPersonalList() {
        List<PersonalTemplateRespVO> allPersonalTemplate = service.getALLPersonalTemplate();
        return success(allPersonalTemplate);
    }

    @GetMapping("/templateList")
    @Operation(summary = "获取模板列表")
    //@PreAuthorize("@ss.hasPermission('system:dept:query')")
    public CommonResult<List<Template>> getList() {
        List<Template> templateList = service.getTemplateList();
        return success(templateList);
    }



    @GetMapping("/get")
    @Operation(summary = "获取个人一键排版")
    @Parameter(name = "id", description = "编号", required = true, example = "1")
    //@PreAuthorize("@ss.hasPermission('system:dept:query')")
    public CommonResult<PersonalTemplateRespVO> getDept(@RequestParam("id") Long id) {
        return success(service.getPersonalTemplateById(id));
    }

}
